package com.ddwl.shop.controller;

import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.schema.bo.shop.DistributionOnOrOffBo;
import com.ddwl.schema.bo.shop.LocalDeliveryBo;
import com.ddwl.schema.bo.shop.LogisticsBo;
import com.ddwl.schema.bo.shop.SelfMentionBo;
import com.ddwl.schema.vo.base.RestVo;
import com.ddwl.schema.vo.shop.ShopDistributionVo;
import com.ddwl.shop.service.ShopDistributionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author hemiaojun
 * @Date 2021/5/22 10:40
 */
@Api(tags = "商户后台配送管理")
@RequestMapping("/distribution/ShopConsole")
@RestController
public class ShopDistributionConsoleController extends BaseController {

    @Resource
    private ShopDistributionService shopDistributionService;


    @GetMapping("/cardList")
    @Auth(product= BaseEnum.ProductEnum.SHOP_CONSOLE)
    @ApiOperation("商户后台获取店铺的配送方式列表")
    public RestVo<ShopDistributionVo> cardList(){
        return RestVo.ok(shopDistributionService.cardList(getShopId()));
    }

    @GetMapping("/get/{id}")
    @Auth(product= BaseEnum.ProductEnum.SHOP_CONSOLE)
    @ApiOperation("商户后台获取不同配送方式的详情")
    public RestVo<ShopDistributionVo> get(@PathVariable("id") String id,
                                          @RequestParam("type") @ApiParam(value = "0快递1同城配送2自提",required = true) Integer type){
        return RestVo.ok(shopDistributionService.get(id,type));
    }

    @PostMapping("/onOrOff")
    @Auth(product = BaseEnum.ProductEnum.SHOP_CONSOLE)
    @ApiOperation("商户后台配送方式开启或关闭")
    public RestVo<Integer> onOrOff(@RequestBody DistributionOnOrOffBo bo){
        bo.setShopId(getShopId());
        return RestVo.ok(shopDistributionService.onOrOff(bo));
    }

    @PostMapping("/selfMention/set")
    @Auth(product = BaseEnum.ProductEnum.SHOP_CONSOLE)
    @ApiOperation("商户后台自提设置")
    public RestVo<String> setSelfMention(@RequestBody SelfMentionBo bo){
        bo.setShopId(getShopId());
        return RestVo.ok(shopDistributionService.setSelfMention(bo));
    }

    @PostMapping("/localDelivery/set")
    @Auth(product = BaseEnum.ProductEnum.SHOP_CONSOLE)
    @ApiOperation("商户后台同城配送设置")
    public RestVo<String> setLocalDelivery(@RequestBody LocalDeliveryBo bo){
        bo.setShopId(getShopId());
        return RestVo.ok(shopDistributionService.setLocalDelivery(bo));
    }

    @PostMapping("/express/set")
    @Auth(product = BaseEnum.ProductEnum.SHOP_CONSOLE)
    @ApiOperation("商户后台快递配送设置")
    public RestVo<String> setExpress(@RequestBody LogisticsBo bo){
        bo.setShopId(getShopId());
        return RestVo.ok(shopDistributionService.setExpress(bo));
    }

}
